﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using ThreeByte.ActiveDeck.Controls;
using ThreeByte.ActiveDeck.Config;

namespace ThreeByte.ActiveDeck.AddIn.Content.Controls
{
    public class ActionButton : Button
    {
        static ActionButton() {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ActionButton), new FrameworkPropertyMetadata(typeof(ActionButton)));
        }

        public static readonly DependencyProperty ActionProperty = DependencyProperty.Register("Action",
            typeof(NavigationAction), typeof(ActionButton));

        public NavigationAction Action {
            get {
                return (NavigationAction)GetValue(ActionProperty);
            }
            set {
                SetValue(ActionProperty, value);
            }
        }

        public ActionButton()
            : base() {

        }

        public override void OnApplyTemplate() {
            base.OnApplyTemplate();

            MenuItem navigateMenuItem = GetTemplateChild("PART_NavigateMenuItem") as MenuItem;
            if(navigateMenuItem != null) {
                navigateMenuItem.Click += new RoutedEventHandler(navigateMenuItem_Click);
            }
        }

        void navigateMenuItem_Click(object sender, RoutedEventArgs e) {
            //Choose which page to jump to
            Console.WriteLine("Jump to");
    
            //Open a new PageChooserForm
            CoreConfig currentConfig = Globals.ThisAddIn.GetCurrentConfig();
            PageChooserControl pageChooser = new PageChooserControl(currentConfig);
            HostForm newDialog = new HostForm(pageChooser);
            if(newDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
                PageConfig selectedPage = pageChooser.SelectedPage;
                Action.Section = selectedPage.ParentSlideConfig.SlideId;
                Action.Page = selectedPage.PageId;
                Action.Jump = true;
            }
        }

    }

    public class ResetButton : Button
    {
        static ResetButton() {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ResetButton), new FrameworkPropertyMetadata(typeof(ResetButton)));
        }
    }

  
}
